<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        
        function longfei() {
            const p = new Promise(function(resolve,reject){
                const time = Math.random() * 3000 + 2000;
                setTimeout(()=>{
                    if(time<3500){
                        resolve({code:1,message:'成功了'})
                    }
                    else{
                        resolve({code:0,message:'失败了'})
                    }
                },time)
            })

                return p;
            }


            async function fn1(){
                const r1 = await longfei();
                
                if(r1.code == 0){
                    console.log('第一个失败了');
                }else{
                    console.log(r1);
                }
                
                const r2 = await longfei();
                
                if(r2.code == 0){
                    console.log('第二个失败了');
                }else{
                    console.log(r2);
                }
                const r3 = await longfei();
                if(r3.code == 0){
                    console.log('第三个失败了');
                }else{
                    console.log(r3);
                }
                const r4 = await longfei();
                
                if(r4.code == 0){
                    console.log('第四个失败了');
                }else{
                    console.log(r4);
                }
            }

            fn1()
    </script>
</body>
</html>